package com.ikas.ai.server.module.condition.service;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikas.ai.server.module.condition.dao.WorkConditionDao;
import com.ikas.ai.server.module.condition.model.WorkCondition;
import com.ikas.ai.server.module.machine.dao.MachineDAO;
import com.ikas.ai.server.module.machine.model.po.Machine;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工况表,工况基础配置
 *
 * @author tang.xuandong
 * @version 1.0.0
 * @date 2023/5/8 09:56
 */
@Service
public class WorkConditionService extends ServiceImpl<WorkConditionDao, WorkCondition> {

    @Autowired
    private MachineDAO machineDAO;

    /**
     * 获取机组信息
     *
     * @return list
     */
    public List<Machine> getMachineList(Integer type) {
        LambdaQueryChainWrapper<Machine> lambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(machineDAO);
        if (type != null) {
            lambdaQueryChainWrapper.eq(Machine::getType, type);
        }
        return lambdaQueryChainWrapper.list();
    }


    /**
     * 根据机组id获取工况列表
     *
     * @param machineId 机组id
     * @return list
     */
    public List<WorkCondition> getWorkConditionByMachineId(Long machineId) {
        if (machineId == null) {
            return null;
        }
        return lambdaQuery().eq(WorkCondition::getMachineId, machineId).list();
    }

    /**
     * 根据机组编号获取工况列表
     *
     * @param machineNo 机组编号
     * @return list
     */
    public List<WorkCondition> getWorkConditionByMachineNo(String machineNo) {
        if (StringUtils.isBlank(machineNo)) {
            return null;
        }
        return lambdaQuery().eq(WorkCondition::getMachineNo, machineNo).list();
    }

    /**
     * 获取机组工况流程基础信息
     *
     * @param machineNo 机组编号
     * @param wfName    工况流程
     */
    public WorkCondition getWorkConditionByMachineNoAndWfName(String machineNo, String wfName) {
        if (StringUtils.isBlank(machineNo) || StringUtils.isBlank(wfName)) {
            return null;
        }
        return lambdaQuery().eq(WorkCondition::getMachineNo, machineNo).eq(WorkCondition::getWfName, wfName).one();
    }

    /**
     * 获取机组工况流程基础信息
     *
     * @param machineNo 机组编号
     * @param wfName    工况流程
     * @param startWc   开始工况
     */
    public WorkCondition getWorkConditionByStartWc(String machineNo, String wfName, String startWc) {
        if (StringUtils.isBlank(machineNo) || StringUtils.isBlank(wfName) || StringUtils.isBlank(startWc)) {
            return null;
        }
        return lambdaQuery().eq(WorkCondition::getMachineNo, machineNo)
                .eq(WorkCondition::getWfName, wfName).eq(WorkCondition::getStartWcName, startWc).one();
    }

}
